package com.lmiot.xyclick.Fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.CardView;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.Html;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.Gson;
import com.lkx.liandianqinew.R;
import com.lmiot.xyclick.AD.SDK.ADSDK;
import com.lmiot.xyclick.Activity.AutoSettingActivity;
import com.lmiot.xyclick.Activity.GroupActivity;
import com.lmiot.xyclick.Activity.GroupControlActivity;
import com.lmiot.xyclick.Activity.MainActivity;
import com.lmiot.xyclick.Activity.PermissionActivity;
import com.lmiot.xyclick.App.MyApp;
import com.lmiot.xyclick.Auto.AutoUtils;
import com.lmiot.xyclick.Bean.ChangeAutoBean;
import com.lmiot.xyclick.Bean.DoAutoBean;
import com.lmiot.xyclick.Bean.InitFloatBean;
import com.lmiot.xyclick.Bean.NewBean.FindDataResBean;
import com.lmiot.xyclick.Bean.PushResultBean;
import com.lmiot.xyclick.Bean.SQL.ActionBean;
import com.lmiot.xyclick.Bean.SQL.ActionBeanSqlUtil;
import com.lmiot.xyclick.Bean.SQL.AutoBean;
import com.lmiot.xyclick.Bean.SQL.AutoBeanSqlUtil;
import com.lmiot.xyclick.Bean.SQL.FriendBean;
import com.lmiot.xyclick.Bean.SQL.FriendBeanSqlUtil;
import com.lmiot.xyclick.Bean.SQL.GroupBean;
import com.lmiot.xyclick.Bean.SQL.GroupBeanSqlUtil;
import com.lmiot.xyclick.Bean.ZxingBean;
import com.lmiot.xyclick.Deving.FloatActivity01;
import com.lmiot.xyclick.Notic.NoticManager;
import com.lmiot.xyclick.Util.ActivityUtil;
import com.lmiot.xyclick.Util.CheckUtil;
import com.lmiot.xyclick.Util.ClickUtils;
import com.lmiot.xyclick.Util.Constants;
import com.lmiot.xyclick.Util.DataUtil;
import com.lmiot.xyclick.Util.DebugUtli;
import com.lmiot.xyclick.Util.DpUtil;
import com.lmiot.xyclick.Util.EditDialogUtil;
import com.lmiot.xyclick.Util.FileUtils;
import com.lmiot.xyclick.Util.FloatManager;
import com.lmiot.xyclick.Util.HttpUtilNew;
import com.lmiot.xyclick.Util.ImgUtil;
import com.lmiot.xyclick.Util.LayoutDialogUtil;
import com.lmiot.xyclick.Util.LogUtil;
import com.lmiot.xyclick.Util.LoopUtils;
import com.lmiot.xyclick.Util.MathUtils;
import com.lmiot.xyclick.Util.NoticUtil;
import com.lmiot.xyclick.Util.PhoneUtil;
import com.lmiot.xyclick.Util.RecordSDK;
import com.lmiot.xyclick.Util.ShortCutUtils;
import com.lmiot.xyclick.Util.TimeUtils;
import com.lmiot.xyclick.Util.ZipUtilOld;
import com.lmiot.xyclick.inteface.OnBasicListener;
import com.uuzuche.lib_zxing.activity.CaptureActivity;
import com.uuzuche.lib_zxing.activity.CodeUtils;
import com.xiaoyi.intentsdklibrary.SDK.Action.ActionAsSDK;
import com.xiaoyi.intentsdklibrary.SDK.Action.ActionNormalSDK;
import com.xiaoyi.intentsdklibrary.SDK.Action.AsconnectBean;
import com.xiaoyi.intentsdklibrary.Utils.ImageUtil;
import com.yanzhenjie.recyclerview.swipe.SwipeMenu;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuBridge;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuCreator;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuItem;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuItemClickListener;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView;
import com.yanzhenjie.recyclerview.swipe.touch.OnItemMoveListener;
import com.yanzhenjie.recyclerview.swipe.touch.OnItemStateChangedListener;
import com.yanzhenjie.recyclerview.swipe.widget.DefaultItemDecoration;
import com.youyi.yyfilepickerlibrary.SDK.YYPickSDK;
import com.youyi.yypermissionlibrary.SDK.OnPerListener;
import com.youyi.yypermissionlibrary.SDK.YYPerUtils;
import com.youyi.yyviewsdklibrary.ArrayGson;
import com.youyi.yyviewsdklibrary.Dialog.util.ToastUtil;
import com.youyi.yyviewsdklibrary.LoadingDialog;
import com.youyi.yyviewsdklibrary.View.TitleBarView;
import com.youyi.yyviewsdklibrary.View.roundedimageview.RoundedImageView;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.builder.GetBuilder;
import com.zhy.http.okhttp.callback.FileCallBack;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import okhttp3.Call;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class AutoFragment extends Fragment implements View.OnClickListener {
    private static final String TAG = "AutoFragment";
    private int REQUEST_CODE = 1891;
    private int REQUEST_IMAGE = 1892;
    private QuickAdapter mAdapter;
    private AutoAdapter mAutoAdapter;
    private List<AutoBean> mAutoDataList;
    private Set<String> mAutoIDList;
    private Set<String> mAutuIDList;
    private Context mContext;
    private Dialog mDialog;
    private Dialog mDialogChose;
    private List<GroupBean> mFileBeanList;
    RecyclerView mFileRecyclerView;
    private String mGroupID;
    private boolean mHasAddItemDecoration = false;
    TextView mIdAddBt;
    TextView mIdDetail;
    LinearLayout mIdEmptyLayout;
    ImageView mIdFriend;
    ImageView mIdGroupHide;
    ImageView mIdGroupShow;
    NestedScrollView mIdNetscrollview;
    LinearLayout mIdPermissionDialogLayout;
    ImageView mIdRecomemtClose;
    TextView mIdRecomemtDetail;
    ImageView mIdRecomemtImg;
    LinearLayout mIdRecomemtLayout;
    TextView mIdRecomemtName;
    ImageView mIdSearch;
    ImageView mIdSearchClose;
    EditText mIdSearchEdit;
    CardView mIdSearchLayout;
    LinearLayout mIdTipLayout;
    TitleBarView mIdTitleBar;
    ImageView mIdYun;
    ImageView mIdZxing;
    ImageView mImgRecord;
    private Intent mIntent;
    private LinearLayoutManager mLayoutManager;
    SwipeMenuRecyclerView mRecyclerView;
    private String mSearchName;

    public AutoFragment() {
    }

    public AutoFragment(Context context) {
        this.mContext = context;
    }

    @Override // android.support.v4.app.Fragment
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(R.layout.fragment_auto, (ViewGroup) null);
        this.mIdPermissionDialogLayout = (LinearLayout) inflate.findViewById(R.id.id_permission_dialog_layout);
        this.mIdTipLayout = (LinearLayout) inflate.findViewById(R.id.id_tip_layout);
        this.mIdRecomemtImg = (ImageView) inflate.findViewById(R.id.id_recomemt_img);
        this.mIdRecomemtName = (TextView) inflate.findViewById(R.id.id_recomemt_name);
        this.mIdRecomemtDetail = (TextView) inflate.findViewById(R.id.id_recomemt_detail);
        this.mIdRecomemtClose = (ImageView) inflate.findViewById(R.id.id_recomemt_close);
        this.mIdRecomemtLayout = (LinearLayout) inflate.findViewById(R.id.id_recomemt_layout);
        this.mIdSearchEdit = (EditText) inflate.findViewById(R.id.id_search_edit);
        this.mIdSearchClose = (ImageView) inflate.findViewById(R.id.id_search_close);
        this.mIdSearchLayout = (CardView) inflate.findViewById(R.id.id_search_layout);
        this.mFileRecyclerView = (RecyclerView) inflate.findViewById(R.id.file_recyclerView);
        this.mIdAddBt = (TextView) inflate.findViewById(R.id.id_add_bt);
        this.mIdDetail = (TextView) inflate.findViewById(R.id.id_detail);
        this.mIdEmptyLayout = (LinearLayout) inflate.findViewById(R.id.id_empty_layout);
        this.mRecyclerView = (SwipeMenuRecyclerView) inflate.findViewById(R.id.recyclerView);
        this.mIdNetscrollview = (NestedScrollView) inflate.findViewById(R.id.id_netscrollview);
        this.mIdTitleBar = (TitleBarView) inflate.findViewById(R.id.id_title_bar);
        this.mImgRecord = (ImageView) inflate.findViewById(R.id.img_record);
        this.mIdZxing = (ImageView) inflate.findViewById(R.id.id_zxing);
        this.mIdFriend = (ImageView) inflate.findViewById(R.id.id_friend);
        this.mIdSearch = (ImageView) inflate.findViewById(R.id.id_search);
        this.mIdGroupShow = (ImageView) inflate.findViewById(R.id.id_group_show);
        this.mIdGroupHide = (ImageView) inflate.findViewById(R.id.id_group_hide);
        this.mIdYun = (ImageView) inflate.findViewById(R.id.id_yun);
        this.mIdPermissionDialogLayout.setOnClickListener(this);
        this.mIdRecomemtClose.setOnClickListener(this);
        this.mIdRecomemtLayout.setOnClickListener(this);
        this.mIdSearchClose.setOnClickListener(this);
        this.mIdSearch.setOnClickListener(this);
        this.mIdAddBt.setOnClickListener(this);
        this.mImgRecord.setOnClickListener(this);
        this.mIdZxing.setOnClickListener(this);
        this.mIdFriend.setOnClickListener(this);
        this.mIdGroupShow.setOnClickListener(this);
        this.mIdGroupHide.setOnClickListener(this);
        this.mIdYun.setOnClickListener(this);
        this.mHasAddItemDecoration = false;
        setDrag();
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        this.mIdTitleBar.setOnItemClickListener(new TitleBarView.onItemClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass1 */

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onTitleClick(View view) {
            }

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onBackClick(View view) {
                AutoUtils.gotAddActionActivity(AutoFragment.this.mContext, "", "", AutoFragment.this.mGroupID);
            }

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onMenuClick(View view) {
                ActivityUtil.skipActivity(AutoFragment.this.mContext, AutoSettingActivity.class);
            }
        });
        this.mRecyclerView.addItemDecoration(new DefaultItemDecoration(getResources().getColor(R.color.transparent), -1, DpUtil.dip2px(MyApp.getContext(), 10.0f), 99));
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.mContext, 1, false);
        this.mLayoutManager = linearLayoutManager;
        this.mRecyclerView.setLayoutManager(linearLayoutManager);
        this.mRecyclerView.setFocusable(false);
        setEdit();
        showPro();
        if (ADSDK.mIsGDT) {
            this.mIdFriend.setVisibility(View.GONE);
        } else {
            this.mIdFriend.setVisibility(View.VISIBLE);
        }
        this.mImgRecord.setOnLongClickListener(new View.OnLongClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass2 */

            public boolean onLongClick(View view) {
                AutoFragment.this.test();
                return true;
            }
        });
        if (DebugUtli.isDebugVersion(MyApp.getContext())) {
            this.mIdZxing.setOnLongClickListener(new View.OnLongClickListener() {
                /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass3 */

                public boolean onLongClick(View view) {
                    ActivityUtil.skipActivity(AutoFragment.this.mContext, FloatActivity01.class);
                    return true;
                }
            });
        }
        return inflate;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(AsconnectBean asconnectBean) {
        if (asconnectBean.isConnect()) {
            checkMethod();
        } else {
            checkMethod();
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(ChangeAutoBean changeAutoBean) {
        if (isVisible()) {
            try {
                ShowGroupListView();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private void showPro() {
        if (DataUtil.nowNoicBean != null) {
            String pro_packName = DataUtil.nowNoicBean.getPro_packName();
            if (!DataUtil.getVip(MyApp.getContext()) || !DataUtil.nowNoicBean.isPro_show()) {
                this.mIdRecomemtLayout.setVisibility(View.GONE);
            } else if (DataUtil.getHasRecommand(MyApp.getContext(), TimeUtils.getAlarmTimeDay())) {
                this.mIdRecomemtLayout.setVisibility(View.GONE);
            } else if (!ActionNormalSDK.getInstance().checkPackName(MyApp.getContext(), pro_packName)) {
                this.mIdRecomemtLayout.setVisibility(View.VISIBLE);
                this.mIdRecomemtName.setText(DataUtil.nowNoicBean.getPro_title());
                this.mIdRecomemtDetail.setText(DataUtil.nowNoicBean.getPro_detail());
                RequestOptions fitCenter = new RequestOptions().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).fitCenter();
                RequestManager with = Glide.with(this.mContext);
                with.load("https://ai.xiaoyizhineng.com:441/download/HelpVideo/autoclick/" + DataUtil.nowNoicBean.getPro_icon()).apply(fitCenter).into(this.mIdRecomemtImg);
            } else {
                this.mIdRecomemtLayout.setVisibility(View.GONE);
            }
        }
    }

    private void setEdit() {
        this.mIdSearchEdit.addTextChangedListener(new TextWatcher() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass4 */

            public void afterTextChanged(Editable editable) {
            }

            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                AutoFragment.this.mSearchName = charSequence.toString();
                if (!TextUtils.isEmpty(AutoFragment.this.mSearchName)) {
                    ArrayList arrayList = new ArrayList();
                    if (AutoFragment.this.mAutoDataList != null && AutoFragment.this.mAutoDataList.size() > 0) {
                        for (AutoBean autoBean : AutoFragment.this.mAutoDataList) {
                            if (autoBean.getAutoName().contains(AutoFragment.this.mSearchName)) {
                                arrayList.add(autoBean);
                            }
                        }
                        if (AutoFragment.this.mAutoAdapter != null) {
                            AutoFragment.this.mAutoAdapter.setData(arrayList, AutoFragment.this.mSearchName);
                        }
                    }
                } else if (AutoFragment.this.mAutoAdapter != null) {
                    AutoFragment.this.mAutoAdapter.setData(AutoFragment.this.mAutoDataList, null);
                }
            }
        });
    }

    private void choseMenu() {
        String str;
        ArrayList arrayList = new ArrayList();
        String recentBackFile = DataUtil.getRecentBackFile(MyApp.getContext());
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.back_save, "备份数据（本地）", null));
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.back_reset, "恢复数据（本地）", null));
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.reset, "恢复本地数据", null));
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.del, "删除所有自动化", null));
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.yun_up, "备份数据(云端，慎用)", null));
        if (TextUtils.isEmpty(recentBackFile)) {
            str = "您还没备份过";
        } else {
            str = "上次:" + recentBackFile;
        }
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.yun_down, "恢复数据(云端，慎用)", str));
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.yun_up, "一次性分享数据", null));
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.yun_down, "恢复指定ID数据", null));
        EditDialogUtil.getInstance().buttomMenuDialog(this.mContext, 9, arrayList, new EditDialogUtil.OnMenuClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass5 */

            @Override // com.lmiot.xyclick.Util.EditDialogUtil.OnMenuClickListener
            public void click(int i) {
                switch (i) {
                    case 0:
                        if (!DataUtil.getVip(MyApp.getContext())) {
                            LayoutDialogUtil.checkVIP(AutoFragment.this.mContext);
                            return;
                        } else {
                            YYPerUtils.sd(AutoFragment.this.mContext, "备份数据需要申请存储权限哦", new OnPerListener() {
                                /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass5.AnonymousClass1 */

                                @Override // com.youyi.yypermissionlibrary.SDK.OnPerListener
                                public void result(boolean z, String str) {
                                    if (z) {
                                        YYPickSDK.getInstance(AutoFragment.this.mContext).choseFolder(new YYPickSDK.OnFolderListener() {
                                            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass5.AnonymousClass1.AnonymousClass1 */

                                            @Override // com.youyi.yyfilepickerlibrary.SDK.YYPickSDK.OnFolderListener
                                            public void result(boolean z, String str, String str2) {
                                                if (z) {
                                                    AutoFragment.this.saveAutoFile(str2);
                                                }
                                            }
                                        });
                                    }
                                }
                            });
                            return;
                        }
                    case 1:
                        if (!DataUtil.getVip(MyApp.getContext())) {
                            LayoutDialogUtil.checkVIP(AutoFragment.this.mContext);
                            return;
                        } else {
                            YYPickSDK.getInstance(AutoFragment.this.mContext).choseFile(ADSDK.saveFileEnd, 1, true, new YYPickSDK.OnPickListener() {

                                @Override // com.youyi.yyfilepickerlibrary.SDK.YYPickSDK.OnPickListener
                                public void result(boolean z, String str, List<String> list) {
                                    if (z) {
                                        AutoFragment.this.resetLocalData(list.get(0));
                                    }
                                }
                            });
                            return;
                        }
                    case 2:
                        FileUtils.resetLocalData(new OnBasicListener() {
                            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass5.AnonymousClass3 */

                            @Override // com.lmiot.xyclick.inteface.OnBasicListener
                            public void result(boolean z, String str) {
                                if (z) {
                                    ToastUtil.success("本地数据恢复成功！");
//                                    EventBus.getDefault().post(new PushResultBean(PushUtils.PUSH_RESULT_CHANGE_DATA, 0, ""));
                                    return;
                                }
                                ToastUtil.err("本地数据恢复失败！");
                            }
                        });
                        return;
                    case 3:
                        AutoFragment.this.showDialog("温馨提醒", "删除后将无法恢复，本地备份也会一起删除；\n\n您是否确定要删除所有的自动化？\n\n", "delall", null, null);
                        return;
                    case 4:
                        if (!DataUtil.getVip(MyApp.getContext())) {
                            LayoutDialogUtil.checkVIP(AutoFragment.this.mContext);
                            return;
                        } else if (AutoBeanSqlUtil.getInstance().searchAll().size() == 0) {
                            ToastUtil.warning("暂时无数据可备份！");
                            return;
                        } else {
                            LayoutDialogUtil.showSureDialog(AutoFragment.this.mContext, "温馨提示", "1.因资源有限，目前云端只会保留一个备份;\n\n2.新上传的备份会覆盖已存在的备份;\n\n3.您确认是否要上传最新备份吗？", true, false, "取消", "确定上传", new LayoutDialogUtil.OnResultClickListener() {
                                /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass5.AnonymousClass4 */

                                @Override // com.lmiot.xyclick.Util.LayoutDialogUtil.OnResultClickListener
                                public void result(boolean z) {
                                    if (z) {
                                        LoadingDialog.show(AutoFragment.this.mContext, LoadingDialog.DialogType.CENTER, true, "");
                                        ZipUtilOld.setStopZipFlag(true);
                                        ZipUtilOld.setStopZipFlag(false);
                                        LoopUtils.zipBackFile(new LoopUtils.onZipFinishListener() {
                                            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass5.AnonymousClass4.AnonymousClass1 */

                                            @Override // com.lmiot.xyclick.Util.LoopUtils.onZipFinishListener
                                            public void result(String str) {
                                                if (!TextUtils.isEmpty(str)) {
                                                    HttpUtilNew.getInstance().upLoadBackFile();
                                                    return;
                                                }
                                                LoadingDialog.hidden();
                                                ToastUtil.err("文件压缩失败！");
                                            }
                                        });
                                    }
                                }
                            });
                            return;
                        }
                    case 5:
                        if (!DataUtil.getVip(MyApp.getContext())) {
                            LayoutDialogUtil.checkVIP(AutoFragment.this.mContext);
                            return;
                        }
                        LoadingDialog.show(AutoFragment.this.mContext, LoadingDialog.DialogType.CENTER, true, "");
                        HttpUtilNew.getInstance().searchBckFile(PhoneUtil.getIMEI(MyApp.getContext()), new HttpUtilNew.OnShareDataListener() {
                            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass5.AnonymousClass5 */

                            @Override // com.lmiot.xyclick.Util.HttpUtilNew.OnShareDataListener
                            public void result(List<FindDataResBean.BodyBean.DataBean.BacklistBean> list) {
                                LoadingDialog.hidden();
                                if (list != null && list.size() > 0) {
                                    try {
                                        String file_context = list.get(0).getFile_context();
                                        FileUtils.checkFolder();
                                        File file = new File(Environment.getExternalStorageDirectory() + "/XYClick", "XYClick.zip");
                                        if (!file.exists()) {
                                            file.createNewFile();
                                        }
                                        FileUtils.base64StringToFileAndReset(file_context, file.getAbsolutePath());
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        });
                        return;
                    case 6:
                        if (!DataUtil.getVip(MyApp.getContext())) {
                            LayoutDialogUtil.checkVIP(AutoFragment.this.mContext);
                            return;
                        } else if (AutoBeanSqlUtil.getInstance().searchAll().size() == 0) {
                            ToastUtil.warning("暂时无数据可备份！");
                            return;
                        } else {
                            LayoutDialogUtil.showSureDialog(AutoFragment.this.mContext, "温馨提示", "1.此功能可以一次性分享所有数据给设备;\n\n2.分享前确认双方APP版本一致，网络没问题;", true, false, "取消", "确定分享", new LayoutDialogUtil.OnResultClickListener() {

                                @Override // com.lmiot.xyclick.Util.LayoutDialogUtil.OnResultClickListener
                                public void result(boolean z) {
                                    if (z) {
                                        FileUtils.checkFolder();
                                        EditDialogUtil.getInstance().share(AutoFragment.this.mContext, 1, "分享所有数据", "请输入设备ID", "", new EditDialogUtil.ShareEditMethod() {
                                            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass5.AnonymousClass6.AnonymousClass1 */

                                            @Override // com.lmiot.xyclick.Util.EditDialogUtil.ShareEditMethod
                                            public void edit(final Set<String> set) {
                                                try {
                                                    LoadingDialog.show(AutoFragment.this.mContext, LoadingDialog.DialogType.CENTER, true, "");
                                                    ZipUtilOld.setStopZipFlag(true);
                                                    ZipUtilOld.setStopZipFlag(false);
                                                    File file = new File(Environment.getExternalStorageDirectory() + "/XYClick", "all.zip");
                                                    if (!file.exists()) {
                                                        new File(file.getParent()).mkdirs();
                                                        file.createNewFile();
                                                    }
                                                    LoopUtils.zipFile(file, new LoopUtils.onZipFinishListener() {
                                                        /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass5.AnonymousClass6.AnonymousClass1.AnonymousClass1 */

                                                        @Override // com.lmiot.xyclick.Util.LoopUtils.onZipFinishListener
                                                        public void result(String str) {
                                                            if (!TextUtils.isEmpty(str)) {
                                                                HttpUtilNew.getInstance().shareAll(str, "_AllUserFile", set);
                                                            }
                                                        }
                                                    });
                                                } catch (IOException e) {
                                                    e.printStackTrace();
                                                }
                                            }
                                        }, false);
                                    }
                                }
                            });
                            return;
                        }
                    case 7:
                        if (!DataUtil.getVip(MyApp.getContext())) {
                            LayoutDialogUtil.checkVIP(AutoFragment.this.mContext);
                            return;
                        } else {
                            EditDialogUtil.getInstance().edit(AutoFragment.this.mContext, 1, "您要恢复数据的ID是", "请输入要恢复数据的ID", "", new EditDialogUtil.EditMethod() {
                                /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass5.AnonymousClass7 */

                                @Override // com.lmiot.xyclick.Util.EditDialogUtil.EditMethod
                                public void edit(String str) {
                                    if (!TextUtils.isEmpty(str)) {
                                        LoadingDialog.show(AutoFragment.this.mContext, LoadingDialog.DialogType.CENTER, true, "");
                                        HttpUtilNew.getInstance().searchBckFile(str, new HttpUtilNew.OnShareDataListener() {
                                            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass5.AnonymousClass7.AnonymousClass1 */

                                            @Override // com.lmiot.xyclick.Util.HttpUtilNew.OnShareDataListener
                                            public void result(List<FindDataResBean.BodyBean.DataBean.BacklistBean> list) {
                                                LoadingDialog.hidden();
                                                if (list != null && list.size() > 0) {
                                                    try {
                                                        String file_context = list.get(0).getFile_context();
                                                        FileUtils.checkFolder();
                                                        File file = new File(Environment.getExternalStorageDirectory() + "/XYClick", "XYClick.zip");
                                                        if (!file.exists()) {
                                                            file.createNewFile();
                                                        }
                                                        FileUtils.base64StringToFileAndReset(file_context, file.getAbsolutePath());
                                                    } catch (Exception e) {
                                                        e.printStackTrace();
                                                    }
                                                }
                                            }
                                        });
                                    }
                                }
                            }, false);
                            return;
                        }
                    default:
                        return;
                }
            }
        }, false, false);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void saveAutoFile(String str) {
        try {
            ZipUtilOld.setStopZipFlag(true);
            ZipUtilOld.setStopZipFlag(false);
            File file = new File(str);
            if (!file.exists()) {
                file.mkdirs();
            }
            File file2 = new File(file, "连点器备份文件" + TimeUtils.getCurrentTimeName() + "." + ADSDK.saveFileEnd);
            if (!file2.exists()) {
                new File(file2.getParent()).mkdirs();
                file2.createNewFile();
            }
            LoopUtils.zipFile(file2, new LoopUtils.onZipFinishListener() {
                /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass6 */

                @Override // com.lmiot.xyclick.Util.LoopUtils.onZipFinishListener
                public void result(String str) {
                    if (!TextUtils.isEmpty(str)) {
                        ToastUtil.success("备份成功：" + str);
                    }
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
            ToastUtil.err("备份失败！");
        }
    }

    public void resetLocalData(String str) {
        LoopUtils.unZipBackFile(new File(str), new LoopUtils.onUnZipFinishListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass7 */

            @Override // com.lmiot.xyclick.Util.LoopUtils.onUnZipFinishListener
            public void result(final boolean z) {
                FileUtils.resetLocalData(new OnBasicListener() {
                    /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass7.AnonymousClass1 */

                    @Override // com.lmiot.xyclick.inteface.OnBasicListener
                    public void result(boolean z, String str) {
                        if (z) {
                            ToastUtil.success("数据恢复成功");
                        } else {
                            ToastUtil.err("数据恢复失败");
                        }
//                        EventBus.getDefault().post(new PushResultBean(PushUtils.PUSH_RESULT_CHANGE_DATA, 0, ""));
                    }
                });
            }
        });
    }

    private void setDrag() {
        new SwipeMenuCreator() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass8 */

            @Override // com.yanzhenjie.recyclerview.swipe.SwipeMenuCreator
            public void onCreateMenu(SwipeMenu swipeMenu, SwipeMenu swipeMenu2, int i) {
                SwipeMenuItem swipeMenuItem = new SwipeMenuItem(AutoFragment.this.mContext);
                swipeMenuItem.setText(R.string.rm);
                swipeMenuItem.setWidth(120);
                swipeMenuItem.setBackgroundColor(AutoFragment.this.getResources().getColor(R.color.colorAccent));
                swipeMenuItem.setHeight(-1);
                swipeMenuItem.setTextColor(-1);
                swipeMenu2.addMenuItem(swipeMenuItem);
            }
        };
        SwipeMenuItemClickListener r0 = new SwipeMenuItemClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass9 */

            @Override // com.yanzhenjie.recyclerview.swipe.SwipeMenuItemClickListener
            public void onItemClick(SwipeMenuBridge swipeMenuBridge) {
                swipeMenuBridge.closeMenu();
                swipeMenuBridge.getDirection();
                swipeMenuBridge.getAdapterPosition();
                swipeMenuBridge.getPosition();
            }
        };
        this.mRecyclerView.setItemViewSwipeEnabled(false);
        this.mRecyclerView.setLongPressDragEnabled(true);
        this.mRecyclerView.setSwipeMenuItemClickListener(r0);
        OnItemMoveListener r02 = new OnItemMoveListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass10 */

            @Override // com.yanzhenjie.recyclerview.swipe.touch.OnItemMoveListener
            public boolean onItemMove(RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder viewHolder2) {
                AutoFragment.this.mAutoAdapter.sortData(viewHolder.getAdapterPosition(), viewHolder2.getAdapterPosition());
                return true;
            }

            @Override // com.yanzhenjie.recyclerview.swipe.touch.OnItemMoveListener
            public void onItemDismiss(RecyclerView.ViewHolder viewHolder) {
                viewHolder.getAdapterPosition();
            }
        };
        this.mRecyclerView.setLongPressDragEnabled(true);
        this.mRecyclerView.setOnItemMoveListener(r02);
        this.mRecyclerView.setOnItemStateChangedListener(new OnItemStateChangedListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass11 */

            @Override // com.yanzhenjie.recyclerview.swipe.touch.OnItemStateChangedListener
            public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int i) {
                if (i == 0) {
                    viewHolder.itemView.setAlpha(1.0f);
                    viewHolder.itemView.findViewById(R.id.id_main).setBackgroundResource(R.drawable.whitebg_5dp);
                    AutoBeanSqlUtil.getInstance().addList(AutoFragment.this.mAutoAdapter.getList());
                } else if (i == 2) {
                    viewHolder.itemView.setAlpha(0.5f);
                    viewHolder.itemView.findViewById(R.id.id_main).setBackgroundResource(R.drawable.color_bg_red);
                }
            }
        });
    }

    @Override // android.support.v4.app.Fragment
    public void onResume() {
        super.onResume();
        int i = 8;
        this.mFileRecyclerView.setVisibility(DataUtil.getHideGroup(this.mContext) ? View.GONE : View.VISIBLE);
        this.mIdGroupShow.setVisibility(DataUtil.getHideGroup(this.mContext) ? View.VISIBLE : View.GONE);
        this.mIdGroupHide.setVisibility(DataUtil.getHideGroup(this.mContext) ? View.GONE : View.VISIBLE);
        this.mAutuIDList = DataUtil.getNoticList(this.mContext);
        this.mIdSearchLayout.setVisibility(DataUtil.getHideSearch(this.mContext) ? View.GONE : View.VISIBLE);
        ImageView imageView = this.mIdSearch;
        if (DataUtil.getHideSearch(this.mContext)) {
            i = View.VISIBLE;
        }
        imageView.setVisibility(i);
        if (this.mIdSearchEdit.getVisibility() == View.VISIBLE) {
            this.mIdSearchEdit.setText("");
        }
        ShowGroupListView();
        checkMethod();
    }

    public void checkMethod() {
        try {
            boolean checkAs = ActionAsSDK.getInstance().checkAs(MyApp.getContext());
            boolean hasOp = YYPerUtils.hasOp();
            boolean hasBgOp = YYPerUtils.hasBgOp();
            boolean checkNotic = CheckUtil.checkNotic(this.mContext);
            if (!checkAs || !hasOp || !checkNotic || !hasBgOp) {
                LinearLayout linearLayout = this.mIdTipLayout;
                if (linearLayout != null) {
                    linearLayout.setVisibility(View.VISIBLE);
                    return;
                }
                return;
            }
            LinearLayout linearLayout2 = this.mIdTipLayout;
            if (linearLayout2 != null) {
                linearLayout2.setVisibility(View.GONE);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void showListView() {
        if (this.mAutoDataList.size() == 0) {
            this.mIdEmptyLayout.setVisibility(View.VISIBLE);
        } else {
            this.mIdEmptyLayout.setVisibility(View.GONE);
        }
        AutoAdapter autoAdapter = new AutoAdapter(this.mAutoDataList);
        this.mAutoAdapter = autoAdapter;
        this.mRecyclerView.setAdapter(autoAdapter);
        this.mRecyclerView.setNestedScrollingEnabled(false);
    }

    public void changeDagta() {
        try {
            ShowGroupListView();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void showRecord() {
        final Dialog createDailog = LayoutDialogUtil.createDailog(this.mContext, R.layout.dialog_xy_record);
        EditText editText = (EditText) createDailog.findViewById(R.id.offset_x);
        EditText editText2 = (EditText) createDailog.findViewById(R.id.offset_y);
        editText.setText(DataUtil.getRecordOffSetX(this.mContext) + "");
        editText2.setText(DataUtil.getRecordOffSetY(this.mContext) + "");
        editText.addTextChangedListener(new TextWatcher() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass12 */

            public void afterTextChanged(Editable editable) {
            }

            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                try {
                    DataUtil.setRecordOffSetX(AutoFragment.this.mContext, MathUtils.parseInt(charSequence.toString()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        editText2.addTextChangedListener(new TextWatcher() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass13 */

            public void afterTextChanged(Editable editable) {
            }

            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                try {
                    DataUtil.setRecordOffSetY(AutoFragment.this.mContext, MathUtils.parseInt(charSequence.toString()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        ((TextView) createDailog.findViewById(R.id.tv_cancel)).setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass14 */

            public void onClick(View view) {
                createDailog.dismiss();
            }
        });
        ((TextView) createDailog.findViewById(R.id.tv_sure)).setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                createDailog.dismiss();
                if (!DataUtil.getVip(MyApp.getContext())) {
                    LayoutDialogUtil.checkVIP(AutoFragment.this.mContext);
                } else {
                    AutoFragment.this.recordMethod();
                }
            }
        });
    }

    private void recordMethod() {
        if (!ActionAsSDK.getInstance().checkAs(MyApp.getContext())) {
            ToastUtil.warning("请先开启无障碍权限！");
            Intent intent = new Intent("android.settings.ACCESSIBILITY_SETTINGS");
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(this.mIntent);
        } else if (RecordSDK.getInstance().isRecording()) {
            ToastUtil.warning("已经中录制中");
        } else {
            FloatManager.show(InitFloatBean.FloatType.record);
            ((MainActivity) this.mContext).refreshView();
        }
    }

    private void zxingMethod() {
        ArrayList arrayList = new ArrayList();
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.chose_camera, "拍照扫描", null));
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.chose_pic, "选择相册", null));
        EditDialogUtil.getInstance().buttomMenuDialog(this.mContext, 4, arrayList, new EditDialogUtil.OnMenuClickListener() {
            @Override // com.lmiot.xyclick.Util.EditDialogUtil.OnMenuClickListener
            public void click(int i) {
                if (i == 0) {
                    YYPerUtils.camera(AutoFragment.this.mContext, "扫描二维码需要申请相机权限哦", new OnPerListener() {
                        /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass16.AnonymousClass1 */

                        @Override // com.youyi.yypermissionlibrary.SDK.OnPerListener
                        public void result(boolean z, String str) {
                            if (z) {
                                AutoFragment.this.startActivityForResult(new Intent(AutoFragment.this.mContext, CaptureActivity.class), AutoFragment.this.REQUEST_CODE);
                                return;
                            }
                            ToastUtil.warning("缺少必要权限");
                        }
                    });
                } else if (i == 1) {
                    YYPerUtils.sd(AutoFragment.this.mContext, "识别相册二维码需要申请存储权限哦", new OnPerListener() {
                        /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass16.AnonymousClass2 */

                        @Override // com.youyi.yypermissionlibrary.SDK.OnPerListener
                        public void result(boolean z, String str) {
                            if (z) {
                                Intent intent = new Intent("android.intent.action.GET_CONTENT");
                                intent.addCategory("android.intent.category.OPENABLE");
                                intent.setType("image/*");
                                AutoFragment.this.startActivityForResult(intent, AutoFragment.this.REQUEST_IMAGE);
                                return;
                            }
                            ToastUtil.warning("缺少必要权限");
                        }
                    });
                }
            }
        }, false, false);
    }

    public void onClick(View view) {
        int i = 0;
        switch (view.getId()) {
            case R.id.id_add_bt /*{ENCODED_INT: 2131296463}*/:
                AutoUtils.gotAddActionActivity(this.mContext, "", "", this.mGroupID);
                return;
            case R.id.id_friend /*{ENCODED_INT: 2131296675}*/:
                ActivityUtil.skipActivity(this.mContext, GroupControlActivity.class);
                return;
            case R.id.id_group_hide /*{ENCODED_INT: 2131296684}*/:
                DataUtil.setHideGroup(this.mContext, true);
                this.mIdGroupHide.setVisibility(View.GONE);
                this.mIdGroupShow.setVisibility(View.VISIBLE);
                this.mFileRecyclerView.setVisibility(View.GONE);
                ShowGroupListView();
                return;
            case R.id.id_group_show /*{ENCODED_INT: 2131296686}*/:
                DataUtil.setHideGroup(this.mContext, false);
                this.mIdGroupShow.setVisibility(View.GONE);
                this.mIdGroupHide.setVisibility(View.VISIBLE);
                this.mFileRecyclerView.setVisibility(View.VISIBLE);
                ShowGroupListView();
                return;
            case R.id.id_permission_dialog_layout /*{ENCODED_INT: 2131296828}*/:
                Intent intent = new Intent(this.mContext, PermissionActivity.class);
                this.mIntent = intent;
                startActivity(intent);
                return;
            case R.id.id_recomemt_close /*{ENCODED_INT: 2131296859}*/:
                DataUtil.setHasRecommand(MyApp.getContext(), TimeUtils.getAlarmTimeDay(), true);
                this.mIdRecomemtLayout.setVisibility(View.GONE);
                return;
            case R.id.id_recomemt_layout /*{ENCODED_INT: 2131296862}*/:
                ArrayList arrayList = new ArrayList();
                arrayList.add(new EditDialogUtil.MenuBean(R.drawable.web, "市场下载", ""));
                arrayList.add(new EditDialogUtil.MenuBean(R.drawable.zxing, "直接下载", ""));
                EditDialogUtil.getInstance().buttomMenuDialog(this.mContext, 4, arrayList, new EditDialogUtil.OnMenuClickListener() {
                    /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass17 */

                    @Override // com.lmiot.xyclick.Util.EditDialogUtil.OnMenuClickListener
                    public void click(int i) {
                        if (i != 0) {
                            if (i == 1 && DataUtil.nowNoicBean != null) {
                                ActionNormalSDK.getInstance().openWeb(AutoFragment.this.mContext, DataUtil.nowNoicBean.getPro_url());
                            }
                        } else if (DataUtil.nowNoicBean != null) {
                            ActionNormalSDK.getInstance().openByMarket(AutoFragment.this.mContext, DataUtil.nowNoicBean.getPro_packName());
                        }
                    }
                }, false, false);
                return;
            case R.id.id_search /*{ENCODED_INT: 2131296886}*/:
                DataUtil.setHideSearch(this.mContext, !DataUtil.getHideSearch(this.mContext));
                this.mIdSearchLayout.setVisibility(DataUtil.getHideSearch(this.mContext) ? View.GONE : View.VISIBLE);
                ImageView imageView = this.mIdSearch;
                if (!DataUtil.getHideSearch(this.mContext)) {
                    i = View.GONE;
                }
                imageView.setVisibility(i);
                return;
            case R.id.id_search_close /*{ENCODED_INT: 2131296889}*/:
                DataUtil.setHideSearch(this.mContext, true);
                this.mIdSearchLayout.setVisibility(View.GONE);
                this.mIdSearch.setVisibility(View.VISIBLE);
                return;
            case R.id.id_yun /*{ENCODED_INT: 2131297017}*/:
                choseMenu();
                return;
            case R.id.id_zxing /*{ENCODED_INT: 2131297020}*/:
                zxingMethod();
                return;
            case R.id.img_record /*{ENCODED_INT: 2131297028}*/:
                showRecord();
                return;
            default:
                return;
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void test() {
        File filesDir = MyApp.getContext().getFilesDir();
        Log.d(TAG, "test00000请求：" + "https://ai.xiaoyizhineng.com:441/download/HelpVideo/autoclick/noticText.txt");
        ((GetBuilder) OkHttpUtils.get().url("https://ai.xiaoyizhineng.com:441/download/HelpVideo/autoclick/noticText.txt")).build().execute(new FileCallBack(filesDir.getAbsolutePath(), "dddd.txt") {
            @Override
            public void onError(Call call, Exception e, int id) {
                Log.d(AutoFragment.TAG, "test00000失败：" + e.getMessage());
            }

            @Override
            public void onResponse(File response, int id) {
                Log.d(AutoFragment.TAG, "test00000成功：" + FileUtils.readFileToString(response));
            }
        });
    }

    public class AutoAdapter extends RecyclerView.Adapter {
        private List<AutoBean> mList;

        @Override // android.support.v7.widget.RecyclerView.Adapter
        public int getItemViewType(int i) {
            return 0;
        }

        public AutoAdapter(List<AutoBean> list) {
            this.mList = list;
        }

        @Override // android.support.v7.widget.RecyclerView.Adapter
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
            return new AutoViewHolder(View.inflate(AutoFragment.this.mContext, R.layout.item_auto, null));
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder viewHolder,int a) {
            String str;
            AutoViewHolder autoViewHolder = (AutoViewHolder) viewHolder;
            final AutoBean autoBean = this.mList.get(a);
            String autoType = autoBean.getAutoType();
            final boolean isEnable = autoBean.getIsEnable();
            if (AutoUtils.hasAs(autoBean)) {
                autoViewHolder.asImg.setVisibility(View.VISIBLE);
            } else {
                autoViewHolder.asImg.setVisibility(View.GONE);
            }
            autoViewHolder.asImg.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    ToastUtil.warning("出现此图标，说明需要开启无障碍才可执行！");
                }
            });
            autoViewHolder.shareImg.setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.Fragment.AutoFragment.AutoAdapter.AnonymousClass2 */

                public void onClick(View view) {
                    ToastUtil.warning("出现此图标，说明是分享或共享市场下载的动作！");
                }
            });
            autoViewHolder.lockedImg.setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.Fragment.AutoFragment.AutoAdapter.AnonymousClass3 */

                public void onClick(View view) {
                    ToastUtil.warning("出现此图标，说明是该动作已经被加密了！");
                }
            });
            boolean isShareAuto = autoBean.getIsShareAuto();
            String password = autoBean.getPassword();
            LogUtil.d(AutoFragment.TAG, "password：" + password);
            if (!isShareAuto) {
                autoViewHolder.shareImg.setVisibility(View.GONE);
                autoViewHolder.lockedImg.setVisibility(View.GONE);
            } else if (TextUtils.isEmpty(password)) {
                autoViewHolder.shareImg.setVisibility(View.VISIBLE);
                autoViewHolder.lockedImg.setVisibility(View.GONE);
            } else {
                autoViewHolder.shareImg.setVisibility(View.GONE);
                autoViewHolder.lockedImg.setVisibility(View.VISIBLE);
            }
            File file = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp", autoBean.getAutoID() + ".jpg");
            int i2 = 1;
            if (file.exists()) {
                autoViewHolder.autoIcon.setImageBitmap(BitmapFactory.decodeFile(file.getAbsolutePath()));
                autoViewHolder.bg.setVisibility(View.GONE);
                autoViewHolder.img.setVisibility(View.GONE);
                autoViewHolder.autoIcon.setVisibility(View.VISIBLE);
            } else {
                autoViewHolder.bg.setVisibility(View.VISIBLE);
                autoViewHolder.img.setVisibility(View.VISIBLE);
                autoViewHolder.autoIcon.setVisibility(View.GONE);
                Glide.with(AutoFragment.this.mContext).load(Integer.valueOf((int) R.drawable.play_auto_blue)).into(autoViewHolder.autoIcon);
                int i3 = a % 5;
                if (i3 == 4) {
                    autoViewHolder.bg.setBackgroundResource(R.drawable.auto_color_other);
                } else if (i3 == 3) {
                    autoViewHolder.bg.setBackgroundResource(R.drawable.auto_color_play);
                } else if (i3 == 2) {
                    autoViewHolder.bg.setBackgroundResource(R.drawable.auto_color_time);
                } else if (i3 == 1) {
                    autoViewHolder.bg.setBackgroundResource(R.drawable.auto_color_screen);
                } else {
                    autoViewHolder.bg.setBackgroundResource(R.drawable.auto_color_text);
                }
            }
            if (TextUtils.isEmpty(autoType)) {
                autoType = "click";
            }
            final String autoName = autoBean.getAutoName();
            if (TextUtils.isEmpty(AutoFragment.this.mSearchName)) {
                autoViewHolder.name.setText(autoName);
            } else {
                autoViewHolder.name.setText(Html.fromHtml(autoName.replace(AutoFragment.this.mSearchName, "<font color='#FF0000'>" + AutoFragment.this.mSearchName + "</font>")));
            }
            int repeatNum = autoBean.getRepeatNum();
            if (repeatNum != 0) {
                i2 = repeatNum;
            }
            TextView textView = autoViewHolder.repeat;
            StringBuilder sb = new StringBuilder();
            sb.append(AutoFragment.this.getString(R.string.r_tt));
            if (i2 == -1) {
                str = AutoFragment.this.getString(R.string.wx);
            } else {
                str = i2 + "";
            }
            sb.append(str);
            sb.append(AutoFragment.this.getString(R.string.ts));
            textView.setText(sb.toString());
            List<ActionBean> searchByID = ActionBeanSqlUtil.getInstance().searchByID(autoBean.getAutoID());
            if (searchByID == null) {
                searchByID = new ArrayList<>();
            }
            autoViewHolder.detail.setText(AutoFragment.this.getString(R.string.ct) + searchByID.size() + AutoFragment.this.getString(R.string.ps));
            autoViewHolder.time.setText(AutoFragment.this.getString(R.string.cr_t) + autoBean.getCreateTime());
            autoViewHolder.more.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    AutoFragment.this.showMoreDialog((AutoBean) AutoAdapter.this.mList.get(a), a);
                }
            });
            if (autoType.equals("click")) {
                Glide.with(AutoFragment.this.mContext).load(Integer.valueOf((int) R.drawable.play_auto)).into(autoViewHolder.img);
                autoViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View view) {
                        AutoFragment autoFragment = AutoFragment.this;
                        String string = AutoFragment.this.getString(R.string.t02);
                        autoFragment.showDialog(string, "您是否要执行：" + autoName, "execute", (AutoBean) AutoAdapter.this.mList.get(a), null);
                    }
                });
            } else if (autoType.equals("time") || autoType.equals("notic") || autoType.equals("screen") || autoType.equals("notic_now") || autoType.equals("screen_now")) {
                if (autoType.equals("time")) {
                    Glide.with(AutoFragment.this.mContext).load(Integer.valueOf(isEnable ? R.drawable.auto_time : R.drawable.auto_time_stop)).into(autoViewHolder.img);
                } else if (autoType.equals("notic") || autoType.equals("notic_now")) {
                    Glide.with(AutoFragment.this.mContext).load(Integer.valueOf(isEnable ? R.drawable.auto_type_msg : R.drawable.auto_type_msg_stop)).into(autoViewHolder.img);
                } else if (autoType.equals("screen") || autoType.equals("screen_now")) {
                    Glide.with(AutoFragment.this.mContext).load(Integer.valueOf(isEnable ? R.drawable.auto_type_screen : R.drawable.auto_type_screen_stop)).into(autoViewHolder.img);
                }
                autoViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                    /* class com.lmiot.xyclick.Fragment.AutoFragment.AutoAdapter.AnonymousClass6 */

                    public void onClick(View view) {
                        AutoFragment.this.mAutoIDList = DataUtil.getNoticList(AutoFragment.this.mContext);
                        if (isEnable) {
                            AutoFragment.this.showDialog(AutoFragment.this.getString(R.string.t02), AutoFragment.this.getString(R.string.uts), "close", autoBean, null);
                        } else {
                            AutoFragment.this.showDialog(AutoFragment.this.getString(R.string.t02), AutoFragment.this.getString(R.string.usd), "open", autoBean, null);
                        }
                    }
                });
            }
            autoViewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                /* class com.lmiot.xyclick.Fragment.AutoFragment.AutoAdapter.AnonymousClass7 */

                public boolean onLongClick(View view) {
                    if (AutoUtils.canEdit(autoBean)) {
                        AutoFragment.this.editAuto(autoBean);
                        return true;
                    }
                    ClickUtils.onlyVibrate(AutoFragment.this.mContext);
                    EditDialogUtil.getInstance().edit(AutoFragment.this.mContext, 1, "该自动化已加密，请输入密码", "请输入密码", "", new EditDialogUtil.EditMethod() {
                        /* class com.lmiot.xyclick.Fragment.AutoFragment.AutoAdapter.AnonymousClass7.AnonymousClass1 */

                        @Override // com.lmiot.xyclick.Util.EditDialogUtil.EditMethod
                        public void edit(String str) {
                            if (FileUtils.decodeString(autoBean.getPassword()).equals(str)) {
                                AutoFragment.this.editAuto(autoBean);
                            } else {
                                ToastUtil.err("密码不正确！");
                            }
                        }
                    }, false);
                    return true;
                }
            });
        }

        @Override // android.support.v7.widget.RecyclerView.Adapter
        public int getItemCount() {
            List<AutoBean> list = this.mList;
            if (list == null) {
                return 0;
            }
            return list.size();
        }

        public void sortData(int i, int i2) {
            try {
                Collections.swap(this.mList, i, i2);
                notifyItemMoved(i, i2);
                for (int i3 = 0; i3 < this.mList.size(); i3++) {
                    this.mList.get(i3).setSortNum((this.mList.size() + 1) - i3);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public List<AutoBean> getList() {
            return this.mList;
        }

        public void setData(List<AutoBean> list, String str) {
            this.mList = list;
            AutoFragment.this.mSearchName = str;
            notifyDataSetChanged();
        }

        private class AutoViewHolder extends RecyclerView.ViewHolder {
            ImageView asImg;
            RoundedImageView autoIcon;
            ImageView bg;
            TextView detail;
            ImageView img;
            ImageView lockedImg;
            ImageView more;
            TextView name;
            TextView repeat;
            ImageView shareImg;
            TextView time;

            public AutoViewHolder(View view) {
                super(view);
                this.bg = (ImageView) view.findViewById(R.id.cb_bg);
                this.img = (ImageView) view.findViewById(R.id.id_img);
                this.more = (ImageView) view.findViewById(R.id.id_auto_more);
                this.name = (TextView) view.findViewById(R.id.id_name);
                this.repeat = (TextView) view.findViewById(R.id.id_repeat);
                this.time = (TextView) view.findViewById(R.id.id_time);
                this.detail = (TextView) view.findViewById(R.id.id_detail);
                this.autoIcon = (RoundedImageView) view.findViewById(R.id.auto_icon);
                this.shareImg = (ImageView) view.findViewById(R.id.id_share);
                this.lockedImg = (ImageView) view.findViewById(R.id.id_locked);
                this.asImg = (ImageView) view.findViewById(R.id.id_as);
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void editAuto(AutoBean autoBean) {
        AutoUtils.editAuto(this.mContext, autoBean);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showMoreDialog(final AutoBean autoBean, int i) {
        Dialog createBottomDailog = LayoutDialogUtil.createBottomDailog(this.mContext, R.layout.dialog_auto_menu);
        this.mDialogChose = createBottomDailog;
        LinearLayout linearLayout = (LinearLayout) createBottomDailog.findViewById(R.id.id_bt01);
        ImageView imageView = (ImageView) this.mDialogChose.findViewById(R.id.id_img01);
        TextView textView = (TextView) this.mDialogChose.findViewById(R.id.id_text01);
        LinearLayout linearLayout2 = (LinearLayout) this.mDialogChose.findViewById(R.id.id_bt02);
        LinearLayout linearLayout3 = (LinearLayout) this.mDialogChose.findViewById(R.id.id_bt03);
        LinearLayout linearLayout4 = (LinearLayout) this.mDialogChose.findViewById(R.id.id_bt04);
        LinearLayout linearLayout5 = (LinearLayout) this.mDialogChose.findViewById(R.id.id_bt05);
        ImageView imageView2 = (ImageView) this.mDialogChose.findViewById(R.id.id_bt05_img);
        LinearLayout linearLayout6 = (LinearLayout) this.mDialogChose.findViewById(R.id.id_bt06);
        LinearLayout linearLayout7 = (LinearLayout) this.mDialogChose.findViewById(R.id.id_bt07);
        LinearLayout linearLayout8 = (LinearLayout) this.mDialogChose.findViewById(R.id.id_bt09);
        TextView textView2 = (TextView) this.mDialogChose.findViewById(R.id.id_cancel);
        String autoType = autoBean.getAutoType();
        if ((TextUtils.isEmpty(autoType) ? "click" : autoType).equals("click")) {
            Glide.with(this.mContext).load(Integer.valueOf((int) R.drawable.auto_ring)).into(imageView);
            textView.setText(R.string.stp);
            linearLayout.setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass19 */

                public void onClick(View view) {
                    if (NoticUtil.isNotificationEnabled(AutoFragment.this.mContext)) {
                        autoBean.setShowNotic(true);
                        AutoBeanSqlUtil.getInstance().add(autoBean);
                        NoticManager.getInstance().updateAutoNotic();
                    } else {
                        ToastUtil.warning(AutoFragment.this.getString(R.string.r_q_n));
                        NoticUtil.toSetting(AutoFragment.this.mContext);
                    }
                    AutoFragment.this.mDialogChose.dismiss();
                }
            });
        } else {
            Glide.with(this.mContext).load(Integer.valueOf((int) R.drawable.auto_test)).into(imageView);
            textView.setText(R.string.tat);
            linearLayout.setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass20 */

                public void onClick(View view) {
                    AutoFragment.this.executeAuto(autoBean);
                    AutoFragment.this.mDialogChose.dismiss();
                }
            });
        }
        linearLayout2.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass21 */

            public void onClick(View view) {
                if (AutoUtils.canEdit(autoBean)) {
                    AutoFragment.this.copyAuto(autoBean);
                } else {
                    ClickUtils.onlyVibrate(AutoFragment.this.mContext);
                    EditDialogUtil.getInstance().edit(AutoFragment.this.mContext, 1, "该自动化已加密，请输入密码", "请输入密码", "", new EditDialogUtil.EditMethod() {
                        /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass21.AnonymousClass1 */

                        @Override // com.lmiot.xyclick.Util.EditDialogUtil.EditMethod
                        public void edit(String str) {
                            if (FileUtils.decodeString(autoBean.getPassword()).equals(str)) {
                                AutoFragment.this.copyAuto(autoBean);
                            } else {
                                ToastUtil.err("密码不正确！");
                            }
                        }
                    }, false);
                }
                AutoFragment.this.mDialogChose.dismiss();
            }
        });
        linearLayout3.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass22 */

            public void onClick(View view) {
                if (AutoUtils.canEdit(autoBean)) {
                    AutoFragment.this.edit(autoBean);
                    return;
                }
                ClickUtils.onlyVibrate(AutoFragment.this.mContext);
                EditDialogUtil.getInstance().edit(AutoFragment.this.mContext, 1, "该自动化已加密，请输入密码", "请输入密码", "", new EditDialogUtil.EditMethod() {
                    /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass22.AnonymousClass1 */

                    @Override // com.lmiot.xyclick.Util.EditDialogUtil.EditMethod
                    public void edit(String str) {
                        if (FileUtils.decodeString(autoBean.getPassword()).equals(str)) {
                            AutoFragment.this.editAuto(autoBean);
                        } else {
                            ToastUtil.err("密码不正确！");
                        }
                    }
                }, false);
            }
        });
        linearLayout4.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass23 */

            public void onClick(View view) {
                AutoFragment autoFragment = AutoFragment.this;
                autoFragment.showDialog(autoFragment.getString(R.string.dl_tip), AutoFragment.this.getString(R.string.ss_d), "del", autoBean, null);
                AutoFragment.this.mDialogChose.dismiss();
            }
        });
        if (MyApp.isMqttConnect) {
            imageView2.setAlpha(1.0f);
        } else {
            imageView2.setAlpha(0.3f);
        }
        linearLayout5.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
//                if (!MyApp.isMqttConnect) {
//                    MyApp.getInstance().connectmqtt();
//                }
                if (!DataUtil.getVip(MyApp.getContext())) {
                    AutoFragment.this.mDialogChose.dismiss();
                    LayoutDialogUtil.checkVIP(AutoFragment.this.mContext);
                    return;
                }
                AutoFragment.this.mDialogChose.dismiss();
                if (AutoUtils.canEdit(autoBean)) {
                    AutoFragment.this.shareAutoID(autoBean.getAutoID(), autoBean.getAutoName());
                    return;
                }
                ClickUtils.onlyVibrate(AutoFragment.this.mContext);
                ToastUtil.err("加密自动化不能被分享！");
            }
        });
        linearLayout6.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass25 */

            public void onClick(View view) {
                FileUtils.checkFolder();
                if (!DataUtil.getVip(MyApp.getContext())) {
                    AutoFragment.this.mDialogChose.dismiss();
                    LayoutDialogUtil.checkVIP(AutoFragment.this.mContext);
                    return;
                }
                LayoutDialogUtil.showSureDialog(AutoFragment.this.mContext, "温馨提示", "请确认已开启以下权限:\n应用管理>权限管理>桌面快捷方式", true, false, "前往开启", "我已开启", new LayoutDialogUtil.OnResultClickListener() {
                    /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass25.AnonymousClass1 */

                    @Override // com.lmiot.xyclick.Util.LayoutDialogUtil.OnResultClickListener
                    public void result(boolean z) {
                        AutoFragment.this.mDialogChose.dismiss();
                        if (z) {
                            File file = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp", autoBean.getAutoID() + ".jpg");
                            if (file.exists()) {
                                ShortCutUtils.addShortcut((Activity) AutoFragment.this.mContext, autoBean.getAutoName(), autoBean.getAutoID(), BitmapFactory.decodeFile(file.getAbsolutePath()));
                            } else {
                                ShortCutUtils.addShortcut((Activity) AutoFragment.this.mContext, autoBean.getAutoName(), autoBean.getAutoID(), BitmapFactory.decodeResource(AutoFragment.this.mContext.getResources(), R.drawable.play_auto_blue));
                            }
                            ToastUtil.success("添加成功1！");
                            return;
                        }
                        ActionNormalSDK.getInstance().gotoSelfSetting(MyApp.getContext());
                    }
                });
            }
        });
        linearLayout7.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass26 */

            public void onClick(View view) {
                AutoFragment.this.mDialogChose.dismiss();
                AutoFragment.this.chosGroudDialog(autoBean);
            }
        });
        linearLayout8.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass27 */

            public void onClick(View view) {
                if (!DataUtil.getVip(MyApp.getContext())) {
                    AutoFragment.this.mDialogChose.dismiss();
                    LayoutDialogUtil.checkVIP(AutoFragment.this.mContext);
                } else if (!DataUtil.getVip(MyApp.getContext())) {
                    AutoFragment.this.mDialogChose.dismiss();
                    LayoutDialogUtil.checkVIP(AutoFragment.this.mContext);
                } else {
                    AutoFragment.this.mDialogChose.dismiss();
                    LoadingDialog.show(AutoFragment.this.mContext, LoadingDialog.DialogType.CENTER, true, "");
                    HttpUtilNew.getInstance().upLoadAutoFile(autoBean.getAutoID(), new OnBasicListener() {
                        /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass27.AnonymousClass1 */

                        @Override // com.lmiot.xyclick.inteface.OnBasicListener
                        public void result(boolean z, String str) {
                            LoadingDialog.hidden();
                            if (z) {
                                AutoFragment.this.showZAutoZxingDialog(autoBean);
                            } else {
                                ToastUtil.err("生成二维码失败，请检查网络!");
                            }
                        }
                    });
                }
            }
        });
        textView2.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass28 */

            public void onClick(View view) {
                AutoFragment.this.mDialogChose.dismiss();
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void copyAuto(AutoBean autoBean) {
        String str;
        String createAutoID = TimeUtils.createAutoID();
        String autoType = autoBean.getAutoType();
        String str2 = createAutoID;
        AutoBean autoBean2 = new AutoBean(null, createAutoID, autoType, autoBean.getAutoName() + getString(R.string.cpy), autoBean.getRepeatNum(), autoBean.getAutoTypeDetail(), autoBean.getIsEnable(), autoBean.getCreateTime(), "666", MyApp.mWidth, MyApp.mHeight, "", "", "", "", false, "", false, "", AutoBeanSqlUtil.getInstance().searchAll().size() + 1, autoBean.getIsRandomRepeat(), autoBean.getRandomMin(), autoBean.getRandomMax(), autoBean.getShowNotic());
        ArrayList arrayList = new ArrayList();
        List<ActionBean> searchByID = ActionBeanSqlUtil.getInstance().searchByID(autoBean.getAutoID());
        if (searchByID != null && searchByID.size() > 0) {
            int i = 0;
            while (i < searchByID.size()) {
                ActionBean actionBean = searchByID.get(i);
                String detail = actionBean.getDetail();
                if (!TextUtils.isEmpty(detail)) {
                    str = str2;
                    detail = detail.replace(autoBean.getAutoID(), str);
                } else {
                    str = str2;
                }
                str2 = str;
                arrayList.add(new ActionBean(null, TimeUtils.createID() + "_" + i, actionBean.getActionName(), actionBean.getActionType(), actionBean.getDelay(), actionBean.getSortNum(), detail, actionBean.getCreateTime(), str2, actionBean.getUseTime(), actionBean.getColor(), actionBean.getColor(), actionBean.getEnable(), actionBean.getUnit(), actionBean.getUuid(), actionBean.getMark()));
                i++;
                arrayList = arrayList;
                searchByID = searchByID;
            }
            ActionBeanSqlUtil.getInstance().addList(str2, arrayList);
        }
        AutoBeanSqlUtil.getInstance().add(autoBean2);
        ToastUtil.success(getString(R.string.cpsy));
        ShowGroupListView();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showZAutoZxingDialog(AutoBean autoBean) {
        Dialog dialog = this.mDialog;
        if (dialog != null) {
            dialog.dismiss();
        }
        Dialog createDailog = LayoutDialogUtil.createDailog(this.mContext, R.layout.dialog_user_zxing);
        this.mDialog = createDailog;
        ImageView imageView = (ImageView) createDailog.findViewById(R.id.id_img);
        final RelativeLayout relativeLayout = (RelativeLayout) this.mDialog.findViewById(R.id.id_code_layout);
        TextView textView = (TextView) this.mDialog.findViewById(R.id.tv_sure);
        TextView textView2 = (TextView) this.mDialog.findViewById(R.id.tv_cancel);
        ((TextView) this.mDialog.findViewById(R.id.tv_title)).setText(autoBean.getAutoName());
        ((TextView) this.mDialog.findViewById(R.id.tv_detail)).setText("动作名称：" + autoBean.getAutoName() + "\n使用方式：应用市场，搜索《连点器》扫描即可使用");
        ZxingBean zxingBean = new ZxingBean();
        zxingBean.setType(Constants.ZXING_TYPE_AUTO);
        zxingBean.setAutoID(autoBean.getAutoID());
        zxingBean.setAutoName(autoBean.getAutoName());
        zxingBean.setUserBrand(PhoneUtil.getBrand());
        zxingBean.setUserModel(PhoneUtil.getModel());
        zxingBean.setUserID(PhoneUtil.getIMEI(MyApp.getContext()));
        Bitmap createImage = CodeUtils.createImage(new Gson().toJson(zxingBean), 500, 500, BitmapFactory.decodeResource(getResources(), R.drawable.icon));
        if (createImage != null) {
            imageView.setImageBitmap(createImage);
        }
        textView.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass29 */

            public void onClick(View view) {
                Bitmap viewToBitmap = ImgUtil.viewToBitmap(relativeLayout);
                String saveBitmpToFile = ImgUtil.saveBitmpToFile(viewToBitmap, PhoneUtil.getIMEI(AutoFragment.this.mContext) + "ZxingCodeAuto");
                if (TextUtils.isEmpty(saveBitmpToFile)) {
                    ToastUtil.err("分享失败！");
                } else {
                    Uri fromFile = Uri.fromFile(new File(saveBitmpToFile));
                    Intent intent = new Intent();
                    intent.setAction("android.intent.action.SEND");
                    intent.putExtra("android.intent.extra.STREAM", fromFile);
                    intent.setType("image/*");
                    AutoFragment.this.startActivity(Intent.createChooser(intent, "分享自动化"));
                }
                AutoFragment.this.mDialog.dismiss();
            }
        });
        textView2.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass30 */

            public void onClick(View view) {
                AutoFragment.this.mDialog.dismiss();
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void edit(AutoBean autoBean) {
        AutoUtils.editAuto(this.mContext, autoBean);
        this.mDialogChose.dismiss();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void chosGroudDialog(final AutoBean autoBean) {
        Dialog dialog = this.mDialog;
        if (dialog != null && dialog.isShowing()) {
            this.mDialog.dismiss();
        }
        Dialog createDailog = LayoutDialogUtil.createDailog(this.mContext, R.layout.dialog_chose_group);
        this.mDialog = createDailog;
        ListView listView = (ListView) createDailog.findViewById(R.id.id_listivew);
        List<GroupBean> searchAll = GroupBeanSqlUtil.getInstance().searchAll();
        if (searchAll.size() > 5) {
            listView.setLayoutParams(new LinearLayout.LayoutParams(-1, DpUtil.dip2px(this.mContext, 300.0f)));
        } else {
            listView.setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
        }
        this.mGroupID = autoBean.getGroupID();
        listView.setAdapter((ListAdapter) new GroupAdapter(searchAll));
        ((TextView) this.mDialog.findViewById(R.id.tv_sure)).setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass31 */

            public void onClick(View view) {
                autoBean.setGroupID(AutoFragment.this.mGroupID);
                AutoBeanSqlUtil.getInstance().add(autoBean);
                AutoFragment.this.ShowGroupListView();
                AutoFragment.this.mDialog.dismiss();
            }
        });
        ((TextView) this.mDialog.findViewById(R.id.tv_cancel)).setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass32 */

            public void onClick(View view) {
                AutoFragment.this.mDialog.dismiss();
            }
        });
    }

    /* access modifiers changed from: private */
    public class GroupAdapter extends BaseAdapter {
        List<GroupBean> list;

        public Object getItem(int i) {
            return null;
        }

        public long getItemId(int i) {
            return 0;
        }

        public GroupAdapter(List<GroupBean> list2) {
            this.list = list2;
        }

        public int getCount() {
            return this.list.size();
        }

        public View getView(final int i, View view, ViewGroup viewGroup) {
            View inflate = View.inflate(AutoFragment.this.mContext, R.layout.item_chose_group, null);
            ImageView imageView = (ImageView) inflate.findViewById(R.id.id_checked);
            ImageView imageView2 = (ImageView) inflate.findViewById(R.id.id_unchecked);
            ((TextView) inflate.findViewById(R.id.id_name)).setText(this.list.get(i).getGroupName());
            if (TextUtils.isEmpty(AutoFragment.this.mGroupID)) {
                AutoFragment.this.mGroupID = "666";
            }
            if (AutoFragment.this.mGroupID.equals(this.list.get(i).getGroupID())) {
                imageView.setVisibility(View.VISIBLE);
                imageView2.setVisibility(View.GONE);
            } else {
                imageView.setVisibility(View.GONE);
                imageView2.setVisibility(View.VISIBLE);
            }
            inflate.setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.Fragment.AutoFragment.GroupAdapter.AnonymousClass1 */

                public void onClick(View view) {
                    AutoFragment.this.mGroupID = GroupAdapter.this.list.get(i).getGroupID();
                    GroupAdapter.this.notifyDataSetChanged();
                }
            });
            return inflate;
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void shareAutoID(final String str, final String str2) {
        EditDialogUtil.getInstance().share(this.mContext, 1, "分享自动化", "请输入设备ID", "", new EditDialogUtil.ShareEditMethod() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass33 */

            @Override // com.lmiot.xyclick.Util.EditDialogUtil.ShareEditMethod
            public void edit(final Set<String> set) {
                LoadingDialog.show(AutoFragment.this.mContext, LoadingDialog.DialogType.CENTER, true, "");
                HttpUtilNew.getInstance().upLoadAutoFile(str, new OnBasicListener() {
                    /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass33.AnonymousClass1 */

                    @Override // com.lmiot.xyclick.inteface.OnBasicListener
                    public void result(boolean z, String str) {
                        LoadingDialog.hidden();
                        if (z) {
//                            PushUtils instance = PushUtils.getInstance();
//                            PushTemplate.PushType pushType = PushTemplate.PushType.NoticAndExtra;
//                            instance.pushList(pushType, set, "收到分享自动化", "自动化名称：" + str2, PushUtils.getInstance().getAdminExtraString(PushUtils.PUSH_TYPE_SHARE, str), new OnBasicListener() {
//
//                                @Override // com.lmiot.xyclick.inteface.OnBasicListener
//                                public void result(boolean z, String str) {
//                                    LogUtil.d(AutoFragment.TAG, "个推：推送结果：isSuccess:" + z);
//                                    LoadingDialog.hidden();
//                                    if (z) {
//                                        ToastUtil.success("分享成功");
//                                    } else {
//                                        ToastUtil.err("分享失败");
//                                    }
//                                }
//                            });
//                            return;
                        }
                        ToastUtil.err("分享失败，请检查网络!");
                    }
                });
            }
        }, false);
    }

    private void showDialog(String str, String str2, final String str3, final AutoBean autoBean, final GroupBean groupBean) {
        LayoutDialogUtil.showSureDialog(this.mContext, str, str2, true, true, "取消", "确定", new LayoutDialogUtil.OnResultClickListener() {

            @Override
            public void result(boolean z) {
                Log.d("lkx_debug","点击确定了 autobean :"+autoBean.toString());
                if (z) {
                    String str = str3;
                    str.hashCode();
                    char c = 65535;
                    switch (str.hashCode()) {
                        case -1335462474:
                            if (str.equals("delall")) {
                                c = 0;
                                break;
                            }
                            break;
                        case -1319569547:
                            if (str.equals("execute")) {
                                c = 1;
                                break;
                            }
                            break;
                        case 99339:
                            if (str.equals("del")) {
                                c = 2;
                                break;
                            }
                            break;
                        case 3417674:
                            if (str.equals("open")) {
                                c = 3;
                                break;
                            }
                            break;
                        case 94756344:
                            if (str.equals("close")) {
                                c = 4;
                                break;
                            }
                            break;
                        case 821510484:
                            if (str.equals("delgroup")) {
                                c = 5;
                                break;
                            }
                            break;
                    }
                    switch (c) {
                        case 0:
                            try {
                                if (YYPerUtils.hasSD()) {
                                    File[] listFiles = new File(Environment.getExternalStorageDirectory() + "/XYClick").listFiles();
                                    for (File file : listFiles) {
                                        if (file.isFile()) {
                                            file.delete();
                                        }
                                    }
                                }
                                List<AutoBean> searchAll = AutoBeanSqlUtil.getInstance().searchAll();
                                if (searchAll.size() > 0) {
                                    for (AutoBean autoBean : searchAll) {
                                        AutoBeanSqlUtil.getInstance().delByID(autoBean.getAutoID());
                                    }
                                }
                            } catch (Exception unused) {
                            }
                            ToastUtil.success("删除成功！");
                            AutoFragment.this.ShowGroupListView();
                            return;
                        case 1:
                            AutoFragment.this.executeAuto(autoBean);
                            return;
                        case 2:
                            String autoID = autoBean.getAutoID();
                            if (autoID == null) {
                                AutoBeanSqlUtil.getInstance().delByName(autoBean.getAutoName());
                            } else if (autoID.equals("null")) {
                                AutoBeanSqlUtil.getInstance().delByName(autoBean.getAutoName());
                            } else {
                                AutoBeanSqlUtil.getInstance().delByID(autoBean.getAutoID());
                            }
                            AutoFragment.this.ShowGroupListView();
                            return;
                        case 3:
                            AutoBean searchByID = AutoBeanSqlUtil.getInstance().searchByID(autoBean.getAutoID());
                            if (searchByID != null) {
                                searchByID.setIsEnable(true);
                                searchByID.setShowNotic(true);
                                AutoBeanSqlUtil.getInstance().add(searchByID);
                            }
                            autoBean.setIsEnable(true);
                            AutoFragment.this.ShowGroupListView();
                            return;
                        case 4:
                            AutoBean searchByID2 = AutoBeanSqlUtil.getInstance().searchByID(autoBean.getAutoID());
                            if (searchByID2 != null) {
                                searchByID2.setIsEnable(false);
                                searchByID2.setShowNotic(false);
                                AutoBeanSqlUtil.getInstance().add(searchByID2);
                            }
                            AutoFragment.this.ShowGroupListView();
                            return;
                        case 5:
                            GroupBeanSqlUtil.getInstance().delByID(groupBean.getGroupID());
                            FileUtils.saveToLocalData("Group.grd", new Gson().toJson(GroupBeanSqlUtil.getInstance().searchAll()));
                            AutoFragment.this.ShowGroupListView();
                            return;
                        default:
                            return;
                    }
                }
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void executeAuto(AutoBean autoBean) {
        if (!AutoUtils.hasAs(autoBean)) {
            EventBus.getDefault().post(new DoAutoBean(101, autoBean, null, 0));
        } else if (ActionAsSDK.getInstance().checkAs(MyApp.getContext())) {
            EventBus.getDefault().post(new DoAutoBean(101, autoBean, null, 0));
        } else {
            try {
                ToastUtil.warning(this.mContext.getString(R.string.optf));
                Intent intent = new Intent("android.settings.ACCESSIBILITY_SETTINGS");
                this.mIntent = intent;
                startActivity(intent);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void ShowGroupListView() {
        try {
            if (!this.mHasAddItemDecoration) {
                DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this.mContext, 0);
                dividerItemDecoration.setDrawable(ContextCompat.getDrawable(this.mContext, R.drawable.divider_source));
                this.mFileRecyclerView.addItemDecoration(dividerItemDecoration);
                this.mHasAddItemDecoration = true;
            }
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.mContext);
            linearLayoutManager.setOrientation(0);
            this.mAdapter = new QuickAdapter();
            this.mFileRecyclerView.setLayoutManager(linearLayoutManager);
            this.mFileRecyclerView.setAdapter(this.mAdapter);
            if (GroupBeanSqlUtil.getInstance().searchByID("666") == null) {
                try {
                    File file = new File(Environment.getExternalStorageDirectory() + "/XYclick/data", "Group.grd");
                    if (file.exists()) {
                        GroupBeanSqlUtil.getInstance().addList(new ArrayGson().fromJsonList(FileUtils.readFileToString(file), GroupBean.class));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            List<GroupBean> searchAll = GroupBeanSqlUtil.getInstance().searchAll();
            this.mFileBeanList = searchAll;
            searchAll.add(new GroupBean(null, "999", "+", 999, null, null));
            String groupID = this.mFileBeanList.get(0).getGroupID();
            this.mGroupID = groupID;
            if (TextUtils.isEmpty(groupID)) {
                this.mGroupID = "666";
            }
            this.mAdapter.replaceData(this.mFileBeanList);
            AutoBeanSqlUtil.getInstance().recoverGroupData();
            if (!DataUtil.getHideGroup(this.mContext)) {
                this.mAutoDataList = AutoBeanSqlUtil.getInstance().searchAllByGroup(this.mGroupID);
            } else {
                this.mAutoDataList = AutoBeanSqlUtil.getInstance().searchAll();
            }
            showListView();
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    public class QuickAdapter extends BaseQuickAdapter<GroupBean, BaseViewHolder> {
        public QuickAdapter() {
            super((int) R.layout.item_h_item);
        }

        /* access modifiers changed from: protected */
        public void convert(BaseViewHolder baseViewHolder, final GroupBean groupBean) {
            if (groupBean.getGroupID().equals("999")) {
                baseViewHolder.setBackgroundRes(R.id.id_filename, R.drawable.group_select_bg_un);
                baseViewHolder.setVisible(R.id.id_img, false);
            }
            if (TextUtils.isEmpty(AutoFragment.this.mGroupID)) {
                AutoFragment.this.mGroupID = "666";
            }
            if (groupBean.getGroupID().equals(AutoFragment.this.mGroupID)) {
                baseViewHolder.setBackgroundRes(R.id.id_filename, R.drawable.group_select_bg);
                baseViewHolder.setVisible(R.id.id_img, true);
                baseViewHolder.setTextColor(R.id.id_filename, -1);
            } else {
                baseViewHolder.setBackgroundRes(R.id.id_filename, R.drawable.group_select_bg_un);
                baseViewHolder.setVisible(R.id.id_img, false);
                baseViewHolder.setTextColor(R.id.id_filename, AutoFragment.this.getResources().getColor(R.color.colorAccent));
            }
            baseViewHolder.setText(R.id.id_filename, groupBean.getGroupName());
            baseViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.Fragment.AutoFragment.QuickAdapter.AnonymousClass1 */

                public void onClick(View view) {
                    if (groupBean.getGroupID().equals("999")) {
                        AutoFragment.this.AddGroupDialog();
                        return;
                    }
                    AutoFragment.this.mGroupID = groupBean.getGroupID();
                    QuickAdapter.this.notifyDataSetChanged();
                    AutoFragment.this.mAutoDataList = AutoBeanSqlUtil.getInstance().searchAllByGroup(AutoFragment.this.mGroupID);
                    AutoFragment.this.showListView();
                }
            });
            baseViewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                /* class com.lmiot.xyclick.Fragment.AutoFragment.QuickAdapter.AnonymousClass2 */

                public boolean onLongClick(View view) {
                    if (groupBean.getGroupID().equals("999")) {
                        return true;
                    }
                    AutoFragment.this.showGroupItemDialog(groupBean);
                    return true;
                }
            });
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showGroupItemDialog(final GroupBean groupBean) {
        ClickUtils.onlyVibrate(this.mContext);
        Dialog dialog = this.mDialogChose;
        if (dialog != null) {
            dialog.dismiss();
        }
        Dialog createBottomDailog = LayoutDialogUtil.createBottomDailog(this.mContext, R.layout.dialog_group);
        this.mDialogChose = createBottomDailog;
        ((LinearLayout) createBottomDailog.findViewById(R.id.id_bt01)).setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass35 */

            public void onClick(View view) {
                AutoFragment.this.mDialogChose.dismiss();
                EditDialogUtil.getInstance().edit(AutoFragment.this.mContext, 1, "分组重命名", "请输入分组名", groupBean.getGroupName(), new EditDialogUtil.EditMethod() {
                    /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass35.AnonymousClass1 */

                    @Override // com.lmiot.xyclick.Util.EditDialogUtil.EditMethod
                    public void edit(String str) {
                        if (GroupBeanSqlUtil.getInstance().searchByName(str) != null) {
                            ToastUtil.warning("已存在相同名称分组！");
                            return;
                        }
                        groupBean.setGroupName(str);
                        GroupBeanSqlUtil.getInstance().add(groupBean);
                        FileUtils.saveToLocalData("Group.grd", new Gson().toJson(GroupBeanSqlUtil.getInstance().searchAll()));
                        AutoFragment.this.ShowGroupListView();
                    }
                }, false);
            }
        });
        ((LinearLayout) this.mDialogChose.findViewById(R.id.id_bt02)).setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass36 */

            public void onClick(View view) {
                AutoFragment.this.mDialogChose.dismiss();
                AutoFragment.this.mIntent = new Intent(AutoFragment.this.mContext, GroupActivity.class);
                AutoFragment.this.mIntent.putExtra("groupID", groupBean.getGroupID());
                AutoFragment.this.mContext.startActivity(AutoFragment.this.mIntent);
            }
        });
        ((LinearLayout) this.mDialogChose.findViewById(R.id.id_bt03)).setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass37 */

            public void onClick(View view) {
                AutoFragment.this.showDialog("温馨提醒", "删除分组不会删除自动化，但会自动分类到默认分组中，您是否要删除该分组？", "delgroup", null, groupBean);
                AutoFragment.this.mDialogChose.dismiss();
            }
        });
        ((TextView) this.mDialogChose.findViewById(R.id.id_cancel)).setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass38 */

            public void onClick(View view) {
                AutoFragment.this.mDialogChose.dismiss();
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void AddGroupDialog() {
        EditDialogUtil.getInstance().edit(this.mContext, 1, "添加分组", "请输入分组名", "", new EditDialogUtil.EditMethod() {
            /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass39 */

            @Override // com.lmiot.xyclick.Util.EditDialogUtil.EditMethod
            public void edit(String str) {
                if (GroupBeanSqlUtil.getInstance().searchByName(str) != null) {
                    ToastUtil.warning("已存在相同名称分组！");
                    return;
                }
                GroupBeanSqlUtil.getInstance().add(new GroupBean(null, TimeUtils.createID(), str, AutoFragment.this.mFileBeanList.size(), TimeUtils.getCurrentTime(), null));
                FileUtils.saveToLocalData("Group.grd", new Gson().toJson(GroupBeanSqlUtil.getInstance().searchAll()));
                AutoFragment.this.ShowGroupListView();
            }
        }, false);
    }

    @Override // android.support.v4.app.Fragment
    public void onDestroyView() {
        super.onDestroyView();
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
    }

    @Override // android.support.v4.app.Fragment
    public void onActivityResult(int i, int i2, Intent intent) {
        Bundle extras;
        super.onActivityResult(i, i2, intent);
        if (i == this.REQUEST_CODE) {
            if (intent != null && (extras = intent.getExtras()) != null) {
                if (extras.getInt(CodeUtils.RESULT_TYPE) == 1) {
                    reslove(extras.getString(CodeUtils.RESULT_STRING));
                } else if (extras.getInt(CodeUtils.RESULT_TYPE) == 2) {
                    ToastUtil.warning("解析二维码失败");
                }
            }
        } else if (i == this.REQUEST_IMAGE && intent != null) {
            try {
                CodeUtils.analyzeBitmap(ImageUtil.getImageAbsolutePath(this.mContext, intent.getData()), new CodeUtils.AnalyzeCallback() {
                    /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass40 */

                    @Override // com.uuzuche.lib_zxing.activity.CodeUtils.AnalyzeCallback
                    public void onAnalyzeSuccess(Bitmap bitmap, String str) {
                        AutoFragment.this.reslove(str);
                    }

                    @Override // com.uuzuche.lib_zxing.activity.CodeUtils.AnalyzeCallback
                    public void onAnalyzeFailed() {
                        ToastUtil.err("解析二维码失败");
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void reslove(String str) {
        try {
            ZxingBean zxingBean = (ZxingBean) new Gson().fromJson(str, ZxingBean.class);
            if (zxingBean != null) {
                String type = zxingBean.getType();
                char c = 65535;
                int hashCode = type.hashCode();
                if (hashCode != 1347678425) {
                    if (hashCode == 1348271861) {
                        if (type.equals(Constants.ZXING_TYPE_USER)) {
                            c = 0;
                        }
                    }
                } else if (type.equals(Constants.ZXING_TYPE_AUTO)) {
                    c = 1;
                }
                if (c == 0) {
                    FriendBeanSqlUtil.getInstance().add(new FriendBean(null, zxingBean.getUserID(), zxingBean.getUserBrand(), zxingBean.getUserBrand(), zxingBean.getUserModel(), "", "", ""));
                    ToastUtil.success("设备添加成功！");
                    ActivityUtil.skipActivity(this.mContext, GroupControlActivity.class);
                } else if (c == 1) {
                    AutoUtils.downAutoData(this.mContext, zxingBean.getUserID(), zxingBean.getAutoID());
                }
            } else if (str.startsWith("#Friend#")) {
                ZxingBean zxingBean2 = (ZxingBean) new com.xiaoyi.intentsdklibrary.Utils.ArrayGson().fromJson(str.replace("#Friend#", ""), ZxingBean.class);
                if (zxingBean2 != null) {
                    FriendBeanSqlUtil.getInstance().add(new FriendBean(null, zxingBean2.getUserID(), zxingBean2.getUserBrand(), zxingBean2.getUserBrand(), zxingBean2.getUserModel(), "", "", ""));
                    ToastUtil.success("设备添加成功！");
                    ActivityUtil.skipActivity(this.mContext, GroupControlActivity.class);
                }
            } else {
                EditDialogUtil.getInstance().sureDialog(this.mContext, "二维码识别结果", str, 0, new EditDialogUtil.setOnSureListener() {
                    /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass41 */

                    @Override // com.lmiot.xyclick.Util.EditDialogUtil.setOnSureListener
                    public void sureClick(boolean z) {
                    }
                }, false);
            }
        } catch (Exception e) {
            e.printStackTrace();
            if (str.startsWith("#Friend#")) {
                ZxingBean zxingBean3 = (ZxingBean) new com.xiaoyi.intentsdklibrary.Utils.ArrayGson().fromJson(str.replace("#Friend#", ""), ZxingBean.class);
                if (zxingBean3 != null) {
                    FriendBeanSqlUtil.getInstance().add(new FriendBean(null, zxingBean3.getUserID(), zxingBean3.getUserBrand(), zxingBean3.getUserBrand(), zxingBean3.getUserModel(), "", "", ""));
                    ToastUtil.success("设备添加成功！");
                    ActivityUtil.skipActivity(this.mContext, GroupControlActivity.class);
                    return;
                }
                return;
            }
            EditDialogUtil.getInstance().sureDialog(this.mContext, "二维码识别结果", str, 0, new EditDialogUtil.setOnSureListener() {
                /* class com.lmiot.xyclick.Fragment.AutoFragment.AnonymousClass42 */

                @Override // com.lmiot.xyclick.Util.EditDialogUtil.setOnSureListener
                public void sureClick(boolean z) {
                }
            }, false);
        }
    }
}
